import sys,os,time
os.chdir("d:/cs1.6server") 
#pid = os.spawnl(os.P_NOWAIT,'D:\cs1.6server\hlds.exe',sys.argv[0])
port = sys.argv[1]
start_map = sys.argv[2]
maxplayers = sys.argv[3]
csconfile =  sys.argv[4]
mapcyclefile = sys.argv[5]
parameters = '-game cstrike +port %s +map %s +maxplayers %s +sv_lan 0 +exec server.cfg +exec %s +mapcycle %s +nomaster -insecure -console' % (port,start_map,maxplayers,csconfile,mapcyclefile)
#print parameters

pid = os.spawnl(os.P_NOWAIT,'D:\cs1.6server\hlds.exe',parameters)
#print parameters
while 1:
	print 'hlds started at %s   ---   port : %s --- map : %s --- maxplayers : %s' % (time.ctime(time.time()),port,start_map,maxplayers)
	os.waitpid(pid,0)
	time.sleep(5)
	pid = os.spawnl(os.P_NOWAIT,'D:\cs1.6server\hlds.exe',parameters)